package com.example.mongo.service;

import com.example.mongo.Model.bean.Shelf;
import com.example.mongo.dao.ShelfMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@CacheConfig(cacheNames = "shelf")
@Service
public class ShelfService  {

    @Autowired
    ShelfMapper shelfMapper;

    @Cacheable
    public List<Shelf> getShelfsById(String id){
        return shelfMapper.getShelfsById(id);
    }

    @Transactional
    public Shelf insertShelf(Shelf shelf){
        shelf.setIsShow(1);
        shelf.setReadTime(new Date());
        return shelfMapper.save(shelf);
    }
   // public User updatePassword(String id);
   @Transactional
   @CachePut
    public Shelf deleteShelf(Shelf shelf){
        shelf.setIsShow(0);
        //shelf.setReadTime(new Date());
        return shelfMapper.save(shelf);
    }
    // public User updatePassword(String id);

    public Shelf getShelfsByComicIdAndId(String id,int comicId){
        return shelfMapper.getShelfsByComicIdAndId(id,comicId);
    }



}
